<template>
  <el-form
    class="drawing-board"
    :size="formConf.size"
    :label-position="formConf.labelPosition"
    :disabled="formConf.disabled"
    :label-width="formConf.labelWidth + 'px'"
  >
    <draggable class="drawing-board" :list="modelVal" :animation="340" group="componentsGroup">
      <el-form-item
        v-for="(component,index) in modelVal"
        :label-width="component.labelWidth"
        :label="component.label"
        :required="component.required"
        :key="index"
      >
        <ComponentRender :conf="component" @input="val => $set(modelVal[index],'defaultValue',val)"/>
      </el-form-item>
    </draggable>
    <div v-show="!modelVal.length" class="empty-info">
      从左侧拖入或点选组件进行表单设计
    </div>
  </el-form>
</template>

<script>
  import ModelMixins from '@/mixins/modelMixins'
  import draggable from 'vuedraggable'
  import ComponentRender from './ComponentRender'

  export default {
    name: 'CenterBoard',
    mixins: [ModelMixins],
    props: {
      formConf: {
        type: Object,
        default: () => ({
          formRef: 'elForm',
          formModel: 'formData',
          size: 'medium',
          labelPosition: 'right',
          labelWidth: 100,
          formRules: 'rules',
          gutter: 15,
          disabled: false,
          span: 24
        })
      }
    },
    components: {
      draggable,
      ComponentRender
    }
  }
</script>

<style scoped lang="scss">
  .drawing-board {
    width: 100%;
    min-height: 600px;
    height: 100%;
    position: relative;
    .empty-info {
      position: absolute;
      top: 46%;
      left: 0;
      right: 0;
      text-align: center;
      font-size: 18px;
      color: #ccb1ea;
      letter-spacing: 4px;
    }
  }
</style>
